<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content="no-cache, no-store, must-revalidate" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    <meta content="0" http-equiv="Expires"/>
    <title></title>
    <link rel="stylesheet" href="../styles/base.css"/>
    <link rel="stylesheet" href="../styles/common.css"/>
    <link rel="stylesheet" href="../styles/font/iconfont.css"/>
    <link rel="stylesheet" href="../styles/jquery.multiselect.filter.css"/>
    <link rel="stylesheet" href="../styles/jquery.multiselect.css"/>
    <link rel="stylesheet" href="../styles/font/iconfont.css"/>
    <link rel="stylesheet" href="../jqueryNicepage/css/layui.css"  media="all">

    <style>
        #body{
            background:#ddecf5;
            overflow-y: scroll;
        }
        .formContent .operatData{
            width:100%;
            max-height:400px;
            overflow-y: scroll;
        }
        .formContent {
            position:relative;
            padding-bottom: 50px;
        }
        .formContent .historyList{
            height:auto;
            overflow: hidden;

        }
        .formContent .historyDataL{
            height:auto;
            width:100%;
            max-height:340px;
            overflow-y: scroll;
            overflow-x: hidden;
        }
        .searchContainer{
            margin-top: 5px;
        }
        .formContent center{
            margin-top: -10px;
        }
        .formContent center #pageBar2{
            position:absolute;
            bottom:-5px;
            width:80%;
            text-align: center;
            /*display:none;*/
        }
    </style>
</head>
<body id="body">
    <div id="loading">
        <img src='../styles/img/loading.gif' />
    </div>
    <div class="searchContainer">
        <div class="seachHeader">
            <span class="headerLeft headerContent"><span>受影响对象:</span><span style="margin-left:3px; border:1px solid #ccc"><input style="padding-left: 5px;" placeholder="请输入受影响对象" maxlength="20" id="searchInput" type="text"/></span></span>
            <span  class="headerLeft headerContent headerRight"><span class="objView">对象视图:</span><select id='select' multiple="multiple">

        </select><button class="searchSureBtn closeBtn">关闭</button><button class="searchSureBtn searchSureBtnBatch">搜索</button></span>
        </div>
        <div class="formContent">
            <h2>单条操作数据展示:</h2>
            <div class="operatData">
                <div style="width: 80%;margin-left:10%;margin-top: -10px;">
                    <div id="table">
                        <table class="layui-table" lay-size="sm">
                            <colgroup> <col width="100"> <col width="300"> <col width="200"> <col width="100"> </colgroup>
                                <div class="noneData"><i class="iconfont">&#xe61e;</i>暂无数据,请搜索</div>
                        </table>
                    </div>
                   <!-- <div id="pageBar2"></div>-->
                </div>
            </div>
            <div class="historyList">
                <h2>历史操作数据展示:</h2>
                <div class="historyDataL">
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../js/common/myAjax.js"></script>
<script type="text/javascript" src="../js/common/utils.js"></script>
<script type="text/javascript" src="../js/common/jquery-ui.min.js"></script>
<script type="text/javascript" src="../js/common/jquery.multiselect.js"></script>
<script src="../layer/layer.js" charset="utf-8"></script>
<script>
    $(function(){
        var textsArr =[];
        var dataLists=[];
        var dataObjArr=[];
        window.ecoid=getQueryStringByNameTwo("oid");
        var height=document.body.clientHeight;
        var width =document.body.clientWidth;
        $("#loading img").css({
            "margin-left":width/2-25+"px",
            "margin-top":height/2-25+"px"
        })
//以下为下拉列表初始配置参数，用户可自行配置，同时，可配置事件参数
        $('#select').multiselect({
            noneSelectedText: "==请选择视图==",
            checkAllText: "全选",
            uncheckAllText: '全不选',
            click:function(event,ui){
                var oHeight = $("#select_ms").height();
                $("#select_ms").css({
                    "overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"
                })
                if(ui.checked){
                    textsArr.push(ui.value)
                }else{
                    var index;
                    if(!textsArr.indexOf){
                        textsArr.indexOf = function(elt /*, from*/){
                            var len = this.length >>> 0;
                            var from = Number(arguments[1]) || 0;
                            from = (from < 0)
                                    ? Math.ceil(from)
                                    : Math.floor(from);
                            if (from < 0)
                                from += len;
                            for (; from < len; from++)
                            {
                                if (from in this &&
                                        this[from] === elt)
                                    return from;
                            }
                            return -1;
                        };
                        index=textsArr.indexOf(ui.value);
                    }else{
                        index= textsArr.indexOf(ui.value);
                    }

                    if(index>(-1)){
                        textsArr.splice(index, 1);
                    }
                }

            },
            selectedText: '# 个被选中',
            selectedList:4
        });
        //加载历史数据
        $("#loading").css({
            display:"none"
        })
        var url1 = "/tmECOHistoryData";
        var oid="oid="+encodeURIComponent(window.ecoid);
        myAjaxHistory(url1,oid,function(str){
            $("#loading").css({
                display:"none"
            })
            if(str.result!=''&&str.result!=undefined){
                layerFn(str.result);
            }else{
                if(str.datalist.length>0){
                    var datArr=[];
                    for(var datL=0;datL<str.datalist.length;datL++){
                        var dataobj={};
                        dataobj.number=str.datalist[datL].number;
                        dataobj.view=str.datalist[datL].view;
                        dataobj.state=str.datalist[datL].state;
                        datArr.push(dataobj)
                    }
                    window.historyList1=datArr;
                    window.headers1=["序号","受影响对象料号","视图","状态","编辑"];
                    window.widths1=[100,300,200,100,200];
                    $(".historyDataL").empty().load('./ecoSearchList.html');
                }else{
                }
            }
        });
        //关闭页面
        $(".closeBtn").click(function(){
            layerFn("确定要关闭此页面",function(){
                window.location.href="about:blank";
                window.opener=null;
                window.open('','_self');
                window.close();
            })
        });

       function getSelectData(datas){
           $("#select").empty();
           for(var dat=0;dat<datas.length;dat++){
               var option = "<option value="+dat+">"+datas[dat].view+"</option>";
               $("#select").append(option);
           }
           $("#select").multiselect('refresh');
       }
        $(".searchSureBtnBatch").click(function(){
            if($("#searchInput").val()==""){
                layerFn("请输入受影响对象");
                return;
            }
           if(textsArr.length>0){
               $(".operatData table thead").remove();
               $(".operatData table tbody").remove();
               /*if(textsArr[0]!=0){
                   layerFn("请选择对象视图");
                   return;
               }*/
               dataObjArr=[];
               for(var data=0;data<textsArr.length;data++){
                   var objcV={}
                   objcV={
                       "searchInputV":dataLists[textsArr[data]].number,
                       "view":dataLists[textsArr[data]].view
                   }
                   dataObjArr.push(objcV);
               }
               if(dataObjArr.length>0){
                   $(".noneData").css({"display":"none"});
                   var T="<thead><tr>  <th>序号</th>  <th>受影响对象料号</th>  <th>视图</th>  <th>编辑</th> </tr></thead> <tbody>";
                   for(var dat=0;dat<dataObjArr.length;dat++){
                       T+=creatrtr(dat,dataObjArr[dat])

                   }
                   function creatrtr(index,h) {
                       // var h = e.split("_");
                       index=index+1;
                       var g = "<tr><td class='serialNumber'>"+index+"</td>";
                       for (var f in h) {
                           g += "<td class='td"+f+"'><input readonly='readonly' unselectable='on'  value='" + h[f] + "'/></td>"
                       }
                       g += "<td class=' ' data-checked=true><i title='操作' class='iconfont fontClickfn'>&#xe606;</i></td></tr>";
                       return g
                   }
                   T+="<tbody/>";
                   $(".operatData table").append(T);

               }

           }else{

               layerFn("请选择对象视图");
               $(".operatData table thead").remove();
               $(".operatData table tbody").remove();
           }

        })
        //
        $("body").on("click",".fontClickfn",function(){
            var otr=$(this).parents("tr")[0];
            var num=$(otr).find(".tdsearchInputV input").val();
            var view=$(otr).find(".tdview input").val();
            window.open("ecotabs.html?num="+num+"&view="+view+"&single="+true+"&oid="+ window.ecoid);

        })
        function suCallback(result){
            //result=eval(result);
            $("#loading").css({
                display:"none"
            });
            //初始化下拉多选框
            $("#select").empty();
            $("#select").multiselect('refresh');
            var inputV=$("#searchInput").val();
           // $(".searchContainer").load("http://localhost:63342/tianma/pages/search.html");
            $("#searchInput").val(inputV);
            if(result.result!=''&&result.result!=undefined){
                layerFn(result.result);
            }
                if(result.datalist.length>0){
                    dataLists=result.datalist;
                    getSelectData(result.datalist);
                }else{
                    if(result.datalist.length==0&&result.result==''){
                        layerFn("您查询的数据在非Design视图中不存在");
                    }

                }
        }
        function errCallback(err){
            $("#loading").css({
                display:"none"
            });
        }
        var initIputVal="" ;
        $("#searchInput").blur(function(){
            //初始化多选框被选数据和渲染数据
            var url = "/tmEcoSingleSearch",
                    data={
                        ecoid:window.ecoid,
                        datalist:[{partnumber:$("#searchInput").val()}]//string
            };
            if($("#searchInput").val()!=""&&initIputVal!=$("#searchInput").val()){
                textsArr=[];
                $(".operatData table tr").remove();
                initIputVal=$("#searchInput").val();
                myAjax(url,data,suCallback,errCallback,"0");
                $("#loading").css({
                    display:"block"
                });

            }else if($("#searchInput").val()==""){
                $(".noneData").css({"display":"block"});
                $(".operatData table tr").remove();
                $("#select").empty();
                $("#select").multiselect('refresh');
                textsArr=[];
            }
        })
        $(".historyDataL").scroll(function() {
            var scrolltop=$(this).scrollTop();
            if(scrolltop>0){
                $("#table2 table thead").css({
                    "position":"absolute",
                    "background":"#f2f2f2",
                    "opacity":"1",
                    "z-index": 999,
                    "top":$(".operatData")[0].offsetHeight+80
                })
            }else{
                $("#table2 table thead").css({
                    "position":""

                })
            }
            for (var i = 0; i <  window.widths1.length; i++) {
                var width = $("#table2 table tbody tr:first-child td").eq(i).width() ;
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                    "width": width+1
                })
            }
        })
        $(".operatData").scroll(function() {
            var scrolltop=$(this).scrollTop();
            if(scrolltop>0){
                $("#table table thead").css({
                    "position":"absolute",
                    "background":"#f2f2f2",
                    "opacity":"1",
                    "z-index": 999,
                    "top":40
                })
            }else{
                $("#table table thead").css({
                    "position":""

                })
            }
            for (var i = 0; i <  4; i++) {
                var width = $("#table table tbody tr:first-child td").eq(i).width() ;
                $("#table .layui-table thead tr:first-child th").eq(i).css({
                    "width": width+1
                })
            }
        })
    })
</script>
</html>